package cn.com.dcsgo.controller;


import cn.com.dcsgo.model.activity.CouponInfo;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.CouponInfoService;
import cn.com.dcsgo.vo.activity.CouponRuleVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/*
请求路径、参数、方式等参考前端文件
uu-preferred-front-end/uuyx-admin/src/api/activity/couponInfo.js
 */

/**
 * <p>
 * 优惠券信息 前端控制器
 * </p>
 *
 * @author Dcsgo
 * @since 2025-04-19
 */
@RequiredArgsConstructor
@Api(tags = "优惠券")
@RestController
@RequestMapping("admin/activity/couponInfo")
public class CouponInfoController {
    private final CouponInfoService couponInfoService;

    @ApiOperation("分页获取优惠卷信息")
    @GetMapping("/{page}/{size}")
    public Result<IPage<CouponInfo>> getPageList(@PathVariable Long page, @PathVariable Integer size) {
        Page<CouponInfo> pageParam = new Page<>(page, size);
        IPage<CouponInfo> result = couponInfoService.getPageList(pageParam);
        return Result.ok(result);
    }

    @ApiOperation("通过id获取优惠卷信息")
    @GetMapping("get/{id}")
    public Result<CouponInfo> getCouponInfo(@PathVariable Long id) {
        CouponInfo result = couponInfoService.getCouponInfo(id);
        return Result.ok(result);
    }

    @ApiOperation("添加优惠卷")
    @PostMapping("save")
    public Result<Serializable> save(@RequestBody CouponInfo couponInfo) {
        couponInfoService.save(couponInfo);
        return Result.ok(null);
    }

    @ApiOperation("根据id更新优惠券信息")
    @PutMapping("/update")
    public Result<Serializable> update(@RequestBody CouponInfo couponInfo) {
        couponInfoService.updateById(couponInfo);
        return Result.ok(null);
    }

    @ApiOperation("根据id删除优惠券")
    @DeleteMapping("remove/{id}")
    public Result<Serializable> remove(@PathVariable Long id) {
        couponInfoService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation("根据id批量删除优惠券")
    @DeleteMapping("batchRemove")
    public Result<Serializable> remove(@RequestBody List<Long> ids) {
        couponInfoService.removeByIds(ids);
        return Result.ok(null);
    }

    @ApiOperation("根据id获取优惠券规则")
    @GetMapping("findCouponRuleList/{id}")
    public Result<Map<String, List<? extends Serializable>>> findCouponRuleList(@PathVariable Long id) {
        Map<String, List<? extends Serializable>> result = couponInfoService.findCouponRuleList(id);
        return Result.ok(result);
    }

    @ApiOperation(value = "添加优惠券规则", notes = "一个商品只能关联一个促销活动或优惠券")
    @PostMapping("/saveCouponRule")
    public Result<Serializable> save(@RequestBody CouponRuleVo couponRuleVo) {
        couponInfoService.save(couponRuleVo);
        return Result.ok(null);
    }
}

